package com.xd.core.finance.controller;


import com.github.pagehelper.Page;
import com.xd.common.constant.SysConstant;
import com.xd.common.util.SecurityUtil;
import com.xd.core.finance.dto.ConsumeDetailQuery;
import com.xd.core.finance.dto.PreDepositeQueryDto;
import com.xd.core.finance.entity.ConsumeDetail;
import com.xd.core.finance.service.IConsumeDetailService;
import com.xd.core.mission.entity.MissionCenterInfo;
import com.xd.core.mission.mapper.MissionCenterInfoMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <p>
 * 服务费消耗明细 前端控制器
 * </p>
 *
 * @author ZX
 * @since 2025-03-18
 */
@Api(tags = "服务费")
@RestController
@RequestMapping("/finance/consume-detail")
public class ConsumeDetailController {

    @Autowired
    private IConsumeDetailService iConsumeDetailService;
    @Autowired
    private MissionCenterInfoMapper missionCenterInfoMapper;


    @PreAuthorize("hasAnyAuthority('sys:ServiceFee-viewDetails')")
    @ApiOperation("服务费消耗明细列表")
    @PostMapping("/getList")
    public Page<ConsumeDetail> getList(@RequestBody ConsumeDetailQuery query) {
        return iConsumeDetailService.getList(query);
    }

    @PreAuthorize("hasAnyAuthority('sys:ServiceFee-Export')")
    @ApiOperation("服务费消耗明细导出")
    @PostMapping("/exportConsumeDetial")
    public void exportConsumeDetial(@RequestBody ConsumeDetailQuery query) {
        //插入数据状态是正在导出
        MissionCenterInfo missionCenterInfo = new MissionCenterInfo();
        missionCenterInfo.setCompanyId(SecurityUtil.getLoginCompanyId());
        missionCenterInfo.setFileStatus(SysConstant.YSZT_FILE_STATUS_ONE);
        missionCenterInfo.setCreateTime(new Date());
        missionCenterInfo.setUserId(SecurityUtil.getLoginUserId());
        missionCenterInfoMapper.insert(missionCenterInfo);
        //获取数据
        iConsumeDetailService.exportConsumeDetail(query, missionCenterInfo.getId());
    }
}
